const children_mainview = [
    {
        path: '/user/feed',
        name: 'Feed',
        component: () => import('@/views/user/home/feed.vue'),
    },
    {
        path: '/user/art-follow',
        name: 'Art-follow',
        component: () => import('@/views/user/home/art-follow.vue'),
    },
    
    {
        path: '/user/art-hot',
        name: 'Art-hot',
        component: () => import('@/views/user/home/art-hot.vue'),
    }
];
const children_userinfo = [
    {
        path: '/user/myarticle',
        name: 'Myarticle',
        component: () => import('@/views/user/myarticle/myarticle.vue')
    },
    {
        path:'/user/followed',
        name:'Followed',
        component: () => import('@/views/user/myself/followed.vue')
    },
    {
        path:'/user/following',
        name:'Following',
        component: () => import('@/views/user/myself/following.vue')
    },
    {
        path:'/user/information',
        name:'Information',
        component: () => import('@/views/user/myself/information.vue')
    },
    {
        path:'/user/subscription',
        name:'Subscription',
        component: () => import('@/views/user/myself/subscription.vue')
    },
];
const children_userinterface = [
    {
        path: '/user/announcement',
        name: 'Announcement',
        component: () => import('@/views/user/announcement/announcement.vue'),
    },
    {
        path: '/user/likeinfo',
        name: 'Likeinfo',
        component: () => import('@/views/user/likeinfo/likeinfo.vue'),
    },
    {
        path: '/user/commentinfo',
        name: 'CommentInfo',
        component: () => import('@/views/user/commentinfo/commentinfo.vue'),
    },
    {
        path: '/user/info',
        name: 'Userinfo',
        component: () => import('@/views/user/info/info.vue'),
        children:children_userinfo
    },
    {
        path: '/user/info/updatepassword',
        name: 'updatePassword',
        component: () => import('@/views/user/info/updatepassword.vue')
    },
    {
        path: '/user/search',
        name: 'Search',
        component: () => import('@/views/user/home/search.vue'),
    },
    {
        path: '/user/mainview',
        name: 'Mainview',
        redirect: '/user/feed',
        component: () => import('@/views/user/home/mainview.vue'),
        children:children_mainview
    }, 
    {
        path: '/user/publisharticle',
        name: 'Pub',
        component: () => import('@/views/user/publisharticle/publisharticle.vue'),
    },
    {
        path: '/user/articledetail',
        name: 'ArticleDetail',
        component: () => import('@/views/user/articledetail/articledetail.vue'),
    },
];
const children1 = [
    {
        path: '/buser/usermanage',
        name: 'Usermanage',
        component: () => import('@/views/buser/usermanage/usermanage.vue')
    },
    {
        path: '/buser/home/mainview',
        name: 'bMainview',
        component: () => import('@/views/buser/home/mainview.vue'),
    }, 
    {
        path: '/buser/articlemanage',
        name: 'Articlemanage',
        component: () => import('@/views/buser/articlemanage/articlemanage.vue'),
    },
    {
        path: '/buser/singlearticlemanage',
        name: 'SingleArticlemanage',
        component: () => import('@/views/buser/articlemanage/singlearticlemanage.vue'),
    },
    {
        path: '/buser/queuemanage',
        name: 'Queuemanage',
        component: () => import('@/views/buser/queuemanage/queuemanage.vue'),
    },
    {
        path: '/buser/info',
        name: 'bUserinfo',
        component: () => import('@/views/buser/info/info.vue')
    },
    {
        path: '/buser/info/updatepassword',
        name: 'bupdatePassword',
        component: () => import('@/views/buser/info/updatepassword.vue')
    },
];

const children_admin_home= [
    {
        path: '/admin/home/info',
        name: 'admininfo',
        component: () => import('@/views/admin/info/info.vue')
    },
    {
        path: '/admin/home/busermanage',
        name: 'bUsermanage',
        component: () => import('@/views/admin/buser/busermanage.vue')
    },
    {
        path: '/admin/home/buserApply',
        name: 'buserApply',
        component: () => import('@/views/admin/buser/buserApply.vue')
    },
    
];

const routes = [

    //访问路由“/”,自动重定向到"/home"   user
    {
        path: '/',
        redirect: '/user/home'
    },
    {
        path: '/user/login',
        name: 'Login',
        component: () => import('@/views/user/login/login.vue'),
    },
    {
        path: '/user/register',
        name: 'Register',
        component: () => import('@/views/user/register/register.vue')
    },
    {
        path: '/user/home',
        name: 'Home',
        redirect: '/user/mainview',
        component: () => import('@/views/user/home/home.vue'),
        children:children_userinterface,
    },
    {
        path: '/404',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    },
    

    //buser
    {
        path: '/buser/home',
        name: 'bHome',
        redirect:'/buser/articlemanage',
        component: () => import('@/views/buser/home/home.vue'),
        children:children1
    },
    {
        path: '/buser/login',
        name: 'bLogin',
        component: () => import('@/views/buser/login/login.vue'),
    },

    //admin
    {
        path: '/admin/home',
        redirect: '/admin/home/busermanage'
    },
    {
        path: '/admin/login',
        name: 'adminLogin',
        component: () => import('@/views/admin/login/login.vue'),
    },
    {
        path: '/admin/home',
        name: 'adminHome',
        component: () => import('@/views/admin/home/home.vue'),
        children:children_admin_home
    },
];

export const existsRoute = (path) => {
    for (let i = 0; i < routes.length; i++) {
        const r = routes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            for (let k = 0; k < r.children.length; k++) {
                const sr = r.children[k];
                if (sr.path == path) {
                    return true;
                }
                if (sr.children && sr.children.length) {
                    for (let j = 0; j < sr.children.length; j++) {
                        const srr = sr.children[j];
                        if (srr.path == path) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
};

export default routes;